package com.atguigu.lease.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
public class MybatisMetaObjectFill implements MetaObjectHandler {
    /**
     * 此类是作为mybatis-plus 给数据库插入或者更新的时候填充字段适用的类
     * insertFill()方法用于插入数据时填充字段
     * updateFill()方法用于更新数据时填充字段
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
